import {Vue, Component} from 'vue-property-decorator';
import { postTradeRecordList} from '@/request/actions'
import PageBottom from '@components/pageBottom/index.vue'



@Component({
    components:{
        PageBottom
    }
})
export default class extends Vue {
    
    salonId:string|number = '';
    userBalance:string|number = 0;
    tabIdx:number = 0;
    userId:string|number = '';
    page:number = 1;
    limit:number = 10;
    list:Array<any> = [];
    triggered:boolean = false;
    bStop:boolean = true;
    loadingType:string|number = 'none';
  
    recordType:any = {
        1:'充值',
        2:'购买商品',
        3:'平台返现',
        4:'提现',
        5:'卖出'
    }


    tab(i:number){
        this.tabIdx = i;
        this.page = 1;
        this.bStop = true;
        this.list = [];
        this.TradeRecordList();
    }

    TradeRecordList(arr:Array<any> = []){
        let userId = this.userId;
        let page = this.page;
        let limit = this.limit;
        let timeStatus = this.tabIdx || null;
        let list:Array<any> = arr;
        let salonId = this.salonId;
        

        uni.showLoading();
        
        postTradeRecordList({salonId,userId,page,limit,timeStatus,orderType:1}).then((r:any)=>{
                let {data:res} = r;

                if(res.status == 200){
                    list.push(...res.data.tradeList);
                    this.list = list;
                    this.userBalance = res.data.userBalance;
              
                    if(res.data.total == 0){
                        this.loadingType = 0;
                       
                    }else if(res.data.total == this.list.length){
                 
                        this.loadingType = 1;

                    }
                }

                this.bStop = res.data.tradeList.length < limit ?  false : true;
                this.triggered = false;
                uni.hideLoading();
        })

    }

    onRefresh(){
        this.list = [];
        this.page = 1;
        this.triggered = true;
        this.bStop = true;
        this.TradeRecordList();

    }

    scrolltolower(){
     
        this.page++;
   
        if(!this.bStop) return;
        
       
        this.TradeRecordList(this.list); 
   }

    onLoad(query:any){  

        this.salonId = query.salonId;
        let globalData = getApp().globalData;
        let {userId} = globalData.userInfo;
        this.userId = userId;
       

        this.TradeRecordList();


    }
}